//
//  PHJMainTabbar.swift
//  新浪微博
//
//  Created by jie peng on 16/5/19.
//  Copyright © 2016年 jie peng. All rights reserved.
//

import UIKit

class PHJMainTabbar: UITabBar {
    
    
     override init(frame: CGRect) {
        super.init(frame: frame)
        
        addSubview(plusBtn)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        
        super.layoutSubviews()
        
        let w = self.bounds.width/5
        let h = self.bounds.height
        let rect = CGRect(x: 0, y: 0, width: w, height: h)
        var index : CGFloat = 0
        
        for subview in subviews{
            
            if subview.isKindOfClass(NSClassFromString("UITabBarButton")!) {
                
                
                subview.frame = CGRectOffset(rect, index*w, 0)
                if index == 1 {
                    index += 1
                }
                index += 1
            }
        
        }
        //MARK:布局新建按钮的frame
        plusBtn.frame = CGRectOffset(rect, 2*w, 0)
        
        
    }
    
    
    
    
    //MARK:懒加载创建一个按钮
    lazy var plusBtn : UIButton = {
       
        let plusBtn = UIButton()
        
        plusBtn.setImage(UIImage(named : "tabbar_compose_icon_add"), forState: .Normal)
        plusBtn.setImage(UIImage(named : "tabbar_compose_icon_add_highlighted"), forState: .Highlighted)
        
        
        plusBtn.setBackgroundImage(UIImage(named : "tabbar_compose_button_highlighted"), forState: .Highlighted)
        plusBtn.setBackgroundImage(UIImage(named : "tabbar_compose_button"), forState: .Normal)
        return plusBtn
    }()

}
